<template>
  <div :class="getBackgroundClass()">
    <div id="nav">
      <navigation/>

      <!--单个回复弹窗-->
      <reply-dialog/>
      <!--发起新私信弹窗-->
      <pm-new-dialog/>
      <!--使用道具弹窗-->
      <item-use-dialog/>
    </div>
    <router-view/>
  </div>
</template>
<script>
import Navigation from "@/components/Navigation.vue";
import {mapActions, mapGetters, mapMutations, mapState} from "vuex";
import ReplyDialog from "@/components/common/dialog/ReplyDialog.vue";
import PmNewDialog from "@/components/common/dialog/PmNewDialog.vue";
import ItemUseDialog from "@/components/common/dialog/ItemUseDialog.vue";

export default {
  components: {ItemUseDialog, PmNewDialog, ReplyDialog, Navigation},
  setup(props, context) {
    let interval;
    return {
      ...mapState("Account", ['currentUid']),
      ...mapMutations('Account', ["accountInit"]),
      ...mapMutations('Resources', ["loadCustomEmotes"]),
      ...mapActions("Resources", ['resourcesInit']),
      ...mapActions("Notice", ['noticeList']),
      ...mapActions("Mission", ['missionAutoCheckInAll']),
      ...mapActions("Block", ['getBlockData']),
      ...mapGetters("Account", ["getClient"]),
      ...mapMutations("Config", ["loadTheme"]),
      ...mapGetters("Config", ["getBackgroundClass"]),
      interval
    }
  },
  mounted() {
    // 加载自定义表情
    this.loadCustomEmotes()
    // 加载主题
    this.loadTheme();
    // 加载账号
    this.accountInit()
    // 加载静态资源
    this.resourcesInit()
    // 提醒消息
    if (this.currentUid()) this.noticeList()

    // 自动完成所有客户端的签到任务
    if (this.currentUid()) this.missionAutoCheckInAll()

    // 定时获取提醒消息
    if (this.interval) {
      clearInterval(this.interval)
    }
    if (this.currentUid()) this.interval = setInterval(() => {
      this.noticeList()
    }, 60 * 1000)

    //初始化屏蔽数据
    if (this.currentUid()) this.getBlockData()
  }
}
</script>
<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  position: sticky;
  top: 3px;
  z-index: 100;
}

#nav a.router-link-exact-active {
  color: #42b983;
}

</style>
